package 贪心算法;

import java.util.Arrays;

public class 用最少数量的箭引爆气球 {

    public static int findMinArrowShots(int[][] points) {
        int n = points.length;
        if (n<2){
            return n;
        }
        //主要是防止超过int范围
        Arrays.sort(points,(a1,a2)->a1[1]<a2[1]?-1:1);
        int res = 1;
        int right = points[0][1];
        for (int i = 1; i < n; i++) {
            if (points[i][0] > right){
                right = points[i][1];
                res++;
            }
        }
        return res;
    }

    public static void main(String[] args) {
        int[][] points ={{-2147483648,-2147483647},{2147483646,2147483647}};
        System.out.println(findMinArrowShots(points));
    }
}
